﻿using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Timo.SqlSugar.DbContext;

public class MultipleDBContext
{
    public readonly SqlSugarClient SugarClient;
    public readonly string Name;
    public MultipleDBContext(IOptionsSnapshot<List<ConnectionConfig>> namedOptionsAccessor)
    {
        SugarClient = new SqlSugarClient(namedOptionsAccessor.Get(this.GetType().Name));
    }

    /// <summary>
    /// 切换库上下文
    /// </summary>
    public SqlSugarProvider GetDbContext(string ConfigId)
    {
        return SugarClient.GetConnection(ConfigId);
    }
}
